<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/assets_header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script src="<%=request.getContextPath()%>/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/jqGrid/i18n/grid.locale-en.js"></script>
<html>
<head>
<script type="text/javascript">
jQuery(document).ready(function() {    
	
	loadGird();
	  
	
});

//初始化列表
function loadGird(){
	var grid_selector = "#grid-table";//列表对象
	var pager_selector = "#grid-pager";//列表分页对象
	jQuery(grid_selector).jqGrid({
		url : "<%=request.getContextPath()%>/base/parameter/list_json",
		datatype : "json",
		height: 400,
		colNames:[/*' ',*/ ' ','moduleName','paramKey','paramDesc','paramScope','paramLevel','paramValue'],
		colModel:[
		{name:'baseParameterId',index:'baseParameterId', width:60, sorttype:"int", hidden: true},
		{name:'moduleName',index:'moduleName',width:90,sortable:false},
		{name:'paramKey',index:'paramKey', width:90,sortable:false},
		{name:'paramDesc',index:'paramDesc', width:90,sortable:false},
		{name:'paramScope',index:'paramScope', width:90,sortable:false},
		{name:'paramLevel',index:'paramLevel', width:90,sortable:false},
		{name:'paramValue',index:'paramValue', width:90,sortable:false}
		], 
		viewrecords : true,
		rowNum:10,
		
		rowList:[10,20,30],
		pager : pager_selector,
		altRows: true,
		multiselect: false,
		 multiboxonly: true,
		 loadComplete : function() {
				
				
			},
		//editurl: $path_base+"/dummy.html",//nothing is saved
		caption: "BaseCompanyInfo List",
		autowidth: true
	});
}

function delUser(){
	 var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
	 }else{
		 bootbox.alert({  
	            buttons: {  
	               ok: {label: '确认',className: 'btn-ok'  }  
	            },  
	            message: '请选择一行数据.',  
	            title: "提示",  
	        });
		 return;
	}
	 var susername = obj.baseParameterId;
	 var id = obj.baseParameterId;
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+susername+"<spring:message code="what"></spring:message>",
		title : "<spring:message code="delete the user"></spring:message>",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/base/parameter/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								$("#grid-table").trigger("reloadGrid"); 
							}else{
								noty({layout: 'center',text: "<spring:message code="delete the user failure"></spring:message>！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'center',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}

function add(){
	location.href="<%=request.getContextPath()%>/base/parameter/form";
}
function edit(){
	var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
		 location.href="<%=request.getContextPath()%>/base/parameter/form?id="+obj.baseParameterId;
	 }
	
}


function search(){
	var val = $("#searchId").val();
    var postData = $("#grid-table").jqGrid("getGridParam", "postData");
    $.extend(postData, {"searchValue":val});
	$("#grid-table").trigger("reloadGrid");
}

</script>
</head>

 
 <body>

	<div class="page-content">
		<div class="page-header">
			<!-- <h1>
				jqGrid
				<small>
					<i class="icon-double-angle-right"></i>
					Dynamic tables and grids using jqGrid plugin
				</small>
			</h1> -->
			<button class="btn btn-xs btn-primary" onclick="add();" id="newBtn">New</button>
			<button class="btn btn-xs btn-primary" onclick="edit();" id="editBtn">Edit</button>
			<button class="btn btn-xs btn-primary" onclick="delUser();" id="deleteBtn">Delete</button>
		</div>
		
		
		<div class="row">
			<div class="col-xs-12">
			<div class="form-group">
				<input type="text" id="searchId" maxlength="30"  class="m-wrap" />
				<button class="btn btn-xs btn-primary" onclick="search();" id="searchBtn">Search</button>
			</div>
			
			<!-- 列表 -->
			<table id="grid-table"></table>
			<!-- 分页 -->
			<div id="grid-pager"></div>
		</div>
		</div>
	</div>

</body>
 </html>